/**
 * Albatross Javascript
 * @author David E. Still
 */
function update_size(size) {
	var size_value = size.options[size.selectedIndex].value;
	albatross.currentSize = size_value;
	var els = $("input");
	for (var i=0; i<els.length; i++) {
		if (els[i].name == "size" && els[i].type == "hidden") { els[i].value = size_value; }
	}
}

function kill_stream() {
	$('#tykiller').remove();
	//$("body").append("<iframe id='tykiller' src='"+albatross.killlink+"' class='nowhere'></iframe>");
	$.get('haltstream.php');
	$("#flash").replaceWith("<div id='flash'></div>");
	$("#player").jqmHide();
}

function load_flash() {
	var flash = null;
	if (useFlowPlayer) {
		flash = new SWFObject("flash/FlowPlayerThermo.swf","single",albatross.sizes[albatross.currentSize].width,albatross.sizes[albatross.currentSize].height,"7");
		flash.addVariable("config", "{ showPlayListButtons: true, playList: [ {overlayId: 'play' }, { url: '"+albatross.streamlink+"' } ], initialScale: 'fit' }");
	} else {
		flash = new SWFObject("flash/mediaplayer.swf","single",albatross.sizes[albatross.currentSize].width,albatross.sizes[albatross.currentSize].height,"7");
		flash.addParam("allowFullScreen","true");
		flash.addVariable("autostart","true");
		flash.addVariable("file",albatross.streamlink);
		flash.addVariable("width",albatross.sizes[albatross.currentSize].width);
		flash.addVariable("height",albatross.sizes[albatross.currentSize].height);
	}
	flash.write("flash");
}

function load_player(){
	setTimeout(function(){
		load_flash();
		var width = (albatross.sizes[albatross.currentSize].width / 1);
		$("#player").jqmShow().css({marginLeft: '-'+Math.floor(width / 2)+'px', 'width': width+'px'});
	}, 1000);
}

var listings = null;
var player = "";
var useFlowPlayer = false;

$(document).ready(function(){
	$("#player").jqm({modal: true, overlay: 70});
	$("table.listings tr").click(function(){
		var forms = $(this).find("form");
		if (forms.length > 0) {
			if (forms.find('input[name=action]').length < 1) {
				forms.submit();
				return;
			}
			var fields = forms.serializeArray();
			$("#player div span.title").html(forms.find('input[name=progname]')[0].value);
			$.ajax({
				type: "get",
				url: "",
				data: fields,
				timeout: 1000,
				complete: load_player
			});
		}
		var links = $(this).find("a.folder");
		if (links.length > 0) { document.location.href = links[0].href; }
	});
	$("table.listings tr").hover(
		function(){
			$(this).find("div.tooltip").show();
		},
		function(){
			$(this).find("div.tooltip").hide();
		}
	);
	$("div.tooltip").hover(function(){ $(this).hide(); }, function(){ return; });
	$("table.listings").tablePager({rowstyles: ["row1","row2"]});
});
